package com.tycmc.common.log;

import com.tycmc.common.util.DateUtil;
import com.tycmc.common.util.Property;

public class AppendLog {

	// 固定部分参数
	private String user;
	private String routingKey;
	private String mdId;
	private String sId;
	private String type;

	public AppendLog() {
		user = Property.getProperty("signal.user");
		routingKey = Property.getProperty("signal.routingKey");
		mdId = Property.getProperty("signal.mdId");
		sId = Property.getProperty("signal.sId");
		type = Property.getProperty("signal.type");

	}

	/**
	 *
	 * @param status
	 *            0代表异常信息，1是正常信息
	 * @param sTime
	 *            源码包接收时间
	 * @param msg
	 *            用户自定义消息(异常的话需包含原始整条信息)
	 * @return
	 */
	public String appendDaily(String status, long sTime, String msg) {

		StringBuilder sb = new StringBuilder();
		try {
			sb.append("{\"user\":").append(user);
			sb.append(",\"routingKey\":").append(routingKey);
			sb.append(",\"message\":{\"sysInfo\":{\"mdId\":").append(mdId);
			sb.append(",\"sId\":").append(sId);
			sb.append(",\"type\":").append(type);
			sb.append(",\"status\":").append(status);
			sb.append(",\"sTime(信息接收时间)\":").append(DateUtil.parseLongToString(sTime));
			sb.append("},\"defInfo\":{\"param_Log\":").append(msg).append("}}}");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sb.toString();
	}

	public String signalStorageMSG(String msg) {
        StringBuilder sb = new StringBuilder();
        try {
            sb.append("{\"layerLevel\":" + 1);
            sb.append(",\"routingKey\":").append(Property.getProperty("rabbitmq.routingkey"));
            sb.append(",\"sTime\":").append(System.currentTimeMillis());
            sb.append(",\"message\":{\"deviceId\":" + "");
            sb.append(",\"owner\":").append(user);
            sb.append(",\"smg\":").append(msg).append("}}");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

}
